package org.chen.result;

import lombok.Data;
import org.chen.service_enum.ErrorCode;

@Data
public class ResultBody<T> {
    private int code;
    private String message;
    private T data;

    public ResultBody() {}

    public ResultBody(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResultBody(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> ResultBody<T> success(T data) {
        return new ResultBody<>(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMessage(), data);
    }

    public static <T> ResultBody<T> success() {
        return new ResultBody<>(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMessage());
    }

    public static <T> ResultBody<T> error(ErrorCode errorCode) {
        return new ResultBody<>(errorCode.getCode(), errorCode.getMessage());
    }

    public static <T> ResultBody<T> error(int code, String message) {
        return new ResultBody<>(code, message);
    }
}
